package io.xccit.train.common.context;

import io.xccit.train.model.member.domain.vo.MemberVO;

/**
 * @author CH_ywx
 * @version 1.0
 * @create 2024/11/13
 * <p>Member信息常量池上下文</p>
 */
public class MemberLoginContext {
    private static final ThreadLocal<MemberVO> MEMBER_THREAD_LOCAL = new ThreadLocal<>();

    /**
     * 获取当前登录用户信息
     * @return
     */
    public static MemberVO getMember(){
        return MEMBER_THREAD_LOCAL.get();
    }

    /**
     * 设置当前登录用户信息
     * @param memberVO
     */
    public static void setMember(MemberVO memberVO){
        MEMBER_THREAD_LOCAL.set(memberVO);
    }

    /**
     * 移除当前登录用户信息
     */
    public static void remove(){
        MEMBER_THREAD_LOCAL.remove();
    }

    /**
     * 获取当前登录用户id
     * @return 当前登录用户ID
     */
    public static Long getId(){
        if (getMember() != null){
            return getMember().getId();
        }
        return null;
    }
}
